﻿using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stardance.ProgramTimer
{
    public class RecordManager
    {
        IScheduler _scheduler;
        public RecordManager()
        {

        }

        public async void OnStart()
        {
            var schedulerFactory = new StdSchedulerFactory();
            _scheduler = await schedulerFactory.GetScheduler();
            await _scheduler.Start();

            _scheduler.JobFactory = new BasicFactory();

            IJobDetail job1 = JobBuilder.Create<RecordJob>().WithIdentity("recordJob", "Group1").Build();

            string cronExpression = ConfigurationManager.AppSettings["Cron"];

            ITrigger trigger1 =
                TriggerBuilder.Create().WithIdentity("Trigger1", "Group1").WithCronSchedule(cronExpression).Build();

            await _scheduler.ScheduleJob(job1, trigger1);
            await _scheduler.Start();
        }

        public void OnStop()
        {

        }

        /// <summary>
        /// 持久化数据
        /// </summary>
        public void OnShutDown()
        {

        }

    }
}
